package com.dc.adaptor.transport.jms;


import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.QueueSender;

import org.apache.log4j.Logger;

import com.dc.adaptor.persistance.bean.SipSendPack;
import com.dc.adaptor.transport.TransportMeta;
import com.dc.adaptor.transport.TransportSender;

public class JmsSender extends JMSTransport implements TransportSender {
	protected Logger logger = Logger.getLogger(this.getClass());

	QueueSender qSender;

	private JmsMeta meta;

	public JmsSender(TransportMeta transportMeta) {
		this.meta = (JmsMeta) transportMeta;
		try {
			qSender = session.createSender(queue);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public Object send(SipSendPack pack) throws Exception {
		Message msg = session.createTextMessage(pack.getSipContent().getContent());
		qSender.send(msg);
		return null;
	}

	@Override
	public void dispose() {
		try {
			qSender.close();
			super.dispose();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
